package com.haizhi.mespush.controller;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.additional.query.impl.QueryChainWrapper;
import com.haizhi.mespush.bean.LFPerson;
import com.haizhi.mespush.bean.Person;
import com.haizhi.mespush.job.HostMesPushJob;
import com.haizhi.mespush.schedule.MyScheduler;
import com.haizhi.mespush.service.LFPersonService;
import com.haizhi.mespush.service.WorkService;
import com.haizhi.mespush.util.Res;
import com.haizhi.mespush.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: Lixiaofei
 * @date: 2020/6/14 0:20
 */
@Controller
public class LoginController {

    @Autowired
    WorkService workService;

    @Autowired
    LFPersonService lfPersonService;

    @RequestMapping("/")
    public String index(){
        return "index";
    }


    /**
     * 获取下一个值班人员  因为放松消息后就会+1
     * @return
     */
    @GetMapping("/getNextIndex")
    @ResponseBody
    public Object getNextIndex(){
        int index = MyScheduler.index;
        List<Person> list =  workService.list(new QueryWrapper<Person>().orderByAsc("no"));
        return list.get(index);
    }

    /**
     * 获取值班列表
     * @return
     */
    @GetMapping("/listOrderList")
    @ResponseBody
    public Object listOrderList(){
        String result = "";
        List<Person> list = workService.list(new QueryWrapper<Person>().orderByAsc("no"));
        for(Person i : list){
            result += i.getName() +'='+ i.getMobile()+ ',';
        }
        return result;
    }

    /**
     * 活雷锋值班列表
     * @return
     */
    @GetMapping("/listLFList")
    @ResponseBody
    public Object listLFList(){
        String result = "";
        List<LFPerson> list = lfPersonService.list();
        for(LFPerson i : list){
            result += Integer.toString(i.getId()) +':'+ i.getNickName()+ ',';
        }
        return result;
    }


    /**
     * 改变顺序
     * @return
     */
    @PostMapping("/changeOrder")
    @ResponseBody
    public String changeOrder(@RequestBody String order) {
        return workService.changeOrder(order);
    }
}
